//////////////////////////////////////////////////////////////////////
////                                                              ////
////  CFMemRead.v                                                 ////
////                                                              ////
////                                                              ////
////  This file is part of the "Pico E12" project                 ////
////  http://www.picocomputing.com                                ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2005, Picocomputing, Inc.                      ////
//// http://www.picocomputing.com/                                ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
////////////////////////////////////////////////////////////////////JF

`timescale 10ns / 1ns

module CFMemRead(CFClock, CardEnabled, OE, WE, IORD, IOWR, REG,
                   MemReadLatch, MemRead, AttribRead, MemReadHold);

input CFClock;                                                        //200 MHz Free Running Oscillator
input CardEnabled;                                                    //Card Enable Signal
input OE;                                                             //Memory Read
input WE;                                                             //Memory Write
input IORD;                                                           //I/O Read
input IOWR;                                                           //I/O Write
input REG;                                                            //Attribute Memory Access

output MemReadLatch;                                                  //Fast Memory Read Latching Signal
output MemRead;                                                       //Delayed Common Memory Read
output AttribRead;                                                    //Delayed Attribute Memory Read (AKA: Configuation Memory)
output MemReadHold;                                                   //Memory Read Hold (Until Card Disconnect)

wire CFClock;
wire CardEnabled;
wire OE;
wire WE;
wire IORD;
wire IOWR;
wire REG;

wire MemReadLatch;
wire MemRead;
wire AttribRead;
wire MemReadHold;

wire RawMemRead;
wire RawAttribRead;
                                                                      //Asynchronous Decoding Logic
assign RawMemRead = (CardEnabled) && (~OE) && (WE) && (IORD) && (IOWR) && (REG);
assign RawAttribRead = (CardEnabled) && (~OE) && (WE) && (IORD) && (IOWR) && (~REG);

assign MemReadLatch = (RawMemRead) || (RawAttribRead);
                                                                      //Instantating this latch aviods HDL Warnings
                                                                      //The clear circutry was added for some Dell laptops that don't de-assert CE (ever)
LDCE MemReadHoldLatch(.Q(MemReadHold), .CLR(~CardEnabled), .D(1'b1), .G(MemReadLatch), .GE(~MemReadHold));

//synthesis attribute init of MemReadHoldLatch is 0;

                                                                      //Delay Lines
RisingAndFallingDelay MemReadDelay(.Clock(CFClock), .In(RawMemRead), .Out(MemRead));
RisingAndFallingDelay AttribReadDelay(.Clock(CFClock), .In(RawAttribRead), .Out(AttribRead));

endmodule